import {Stack} from "./Stack.ts";
import Order from "./Order.ts";
import {LineBook} from "./LineBook.ts";
import {UserAccount} from "./UserAccount.ts";
import Book from "./Book.ts";

export type TableData = {
    [key: string]: string | number | LineBook[] | bigint;
}


export const convertStacksToTableData = (stacks: Stack[]): TableData[] => {
    return stacks.map(stack => {
        return {
            stackId: stack.stackId,
            categoryId: stack.categoryId,
            imgUrl: stack.imageUrl,
            title: stack.title,
            description: stack.description,
            author: stack.author,
            status: stack.status,
            quantity: stack.quantity
        };
    });
};

export const convertBooksToTableData = (books: Book[]): TableData[] => {
    return books.map(book => {
        return {
            bookId: book.bookId,
            categoryId: book.categoryId,
            stackId: book.stackId,
            ownerId: book.ownerId,
            condition: book.condition,
            fee: book.fee,
            price: book.price,
            imgUrl: book.imageUrl,
            status: book.status,
        };
    });
};

export const convertOrdersToTableData = (orders: Order[]): TableData[] => {
    return orders.map(order => {
        return {
            orderId: order.orderId,
            userId: order.userId,
            dateCreated: order.dateCreated,
            status: order.status,
            quantity: order.quantity,
            class: order.class,
            listBooks: order.listBooks
        };
    });
};


export const convertUserAccountsToTableData = (users: UserAccount[]): TableData[] => {
    return users.map(user => {
        return {
            userId: user.userId,
            type: user.type,
            borrowLimit: user.borrowLimit,
            firstName: user.firstName,
            lastName: user.lastName,
            email: user.email,
            address: user.address,
            imageUrl: user.imageUrl,
            listBooks: user.listBooks
        };
    });
};